/**
 * 维度管理初始化
 */
var Dimension = {
    id: "DimensionTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Dimension.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: '序号', field: 'num', align: 'center', valign: 'middle', sortable: true},
        {title: '维度中文名', field: 'dimensionChinaName', align: 'center', valign: 'middle', sortable: true},
        {title: '维度英文名', field: 'dimensionEnglishName', align: 'center', valign: 'middle', sortable: true},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true}];
};

Dimension.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Dimension.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
Dimension.openAddDimension = function () {
    var index = layer.open({
        type: 2,
        title: '添加维度',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/dimension/dimension_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看维度详情
 */
Dimension.openDimensionDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '维度详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/dimension/dimension_update/' + Dimension.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除维度
 */
Dimension.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/dimension/delete/" + this.seItem.id, function (data) {
            Feng.success("删除成功!");
            Dimension.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Dimension.formParams = function () {
    var queryData = {};
    queryData['dimensionName'] = $("#dimensionName").val();
    return queryData;
}

Dimension.resetSearch = function () {
    $("#dimensionName").val("");
    Dimension.search();
};

/**
 * 查询列表
 */
Dimension.search = function () {
    Dimension.table.refresh({query: Dimension.formParams()});
};

$(function () {
    var defaultColunms = Dimension.initColumn();
    var table = new BSTable(Dimension.id, "/dimension/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Dimension.formParams());
    Dimension.table = table.init();
    Dimension.table = table;
});
